<template>
  <el-container>
    <!-- 侧栏 -->
    <el-aside width="200px">
      <img src="../../assets/img/logo.jpg" alt="" class="logo" style="height:85px">
      <subMune></subMune>
    </el-aside>
    <el-container>
      <!-- 顶栏 -->
      <el-header>
        <el-row type="flex" class="row-bg" justify="space-between">
          <el-col :span="6">
            <div class="grid-content shouqi" @click="isCollapse">
              <i :class="menuCollapseIcon"></i>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content title">寰球旅游管理系统</div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content info">
              <el-avatar :src="arr.headimgurl?arr.headimgurl:avtarUrl"></el-avatar>
              <span class="nickname">
                {{arr.nickname}}
              </span>
              <a href="javascript:;" class="quit" @click="quit">退出</a>
            </div>
          </el-col>
        </el-row>
      </el-header>
      <!-- 主体 -->
      <el-main>
        <el-breadcrumb separator=">">
          <el-breadcrumb-item :to="{path:'/'}">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ name:item.name }" 
          v-for="(item,index) in crumbs"
          :key="index">{{item.meta.name}}</el-breadcrumb-item>
         
        </el-breadcrumb>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  // import * as api from "@/api"
  import {
    mapState
  } from "vuex"
  import subMune from "../../components/subMune"
  import {
    getLoginLogApi,
    getMenuListApi
  } from "../../api"
  // import recursionRoutes from '@/utils/recursionRoutes'
  // import allRoutes from '@/router/allRoutes'
  export default {
    created() {
      this.arr = JSON.parse(localStorage.getItem("userInfo"))
      // console.log(this.arr);

    },
    data() {
      return {
        arr: {},
        avtarUrl: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",

      }
    },
    components: {
      subMune
    },
    computed: {
      ...mapState(["menuCollapse","crumbs"]),
      menuCollapseIcon() {
        return this.menuCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
      }
    },
    methods: {
      quit() { //退出登录
        // 跳转页面
        this.$router.push("/login")
        // 清除localstorage的hq-token
        localStorage.removeItem("hq-token")
        localStorage.removeItem("userInfo")
        // 因为addRoutes不能删除，所以我们要重新刷新页面
        location.reload()
      },
      isCollapse() {
        this.$store.commit("SET_MENU_COLLAPSE")
      }
    },
    mounted() {
      // 获取登录日志
      getLoginLogApi()
        .then(res => {
          // console.log(res);
        })
      // 获取权限菜单
      getMenuListApi()
      .then(res=>{
        // console.log(res);
        // console.log(recursionRoutes(allRoutes,res.data.menuList));

      })
    }
  }
</script>
<style scoped lang="less">
  .el-header,
  .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    // line-height: 60px;
  }

  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
  }

  .el-main {
    background-color: #E9EEF3;
    color: #333;
  }

  .el-container {
    margin-bottom: 40px;
    height: 100%;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

  .el-row {
    margin-bottom: 20px;

    &:last-child {
      margin-bottom: 0;
    }
  }

  .el-col {
    border-radius: 4px;
  }

  .bg-purple-dark {
    background: #99a9bf;
  }

  .bg-purple {
    background: #d3dce6;
  }

  .bg-purple-light {
    background: #e5e9f2;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }

  .row-bg {
    padding: 10px 0;
    background-color: skyblue;
    color: white;
  }

  .el-icon-s-fold {
    font-size: 40px;
    color: black;
  }

  .shouqi {
    text-align: left;
    cursor: pointer;
  }

  .el-icon-s-unfold {
    font-size: 40px;
    color: black;
  }

  .title {
    line-height: 40px;
    font-size: 22px;
  }

  .el-avatar--circle {
    vertical-align: middle;
  }

  .nickname {
    margin: 0 10px;
  }
</style>